/**
 * @description Axios封装
 */

import Axios from 'axios';

const Request = Axios.create({
    baseURL: `xxxxxxxxxx.com`,
    timeout: 10000,
})

type AxiosReturnType = {
    data: any
    code: number
}

Request.interceptors.request.use(
    config => {
        return config
    },
    error => {
        return Promise.reject(error);
    }
)

Request.interceptors.response.use(
    <T extends AxiosReturnType, Response extends { data: T }>(response: Response): T => {
        return response.data
    },
    error => {
        return Promise.reject(error);
    }
)

export default {
    get<T extends Object>(url: string, params: T) {
        return Request.get(url, params)
    },
    post<T extends Object>(url: string, params: T) {
        return Request.post(url, params)
    }
}